<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            var findLength = function (nums1, nums2) {
                let result = 0
                let dp = new Array(nums1.length + 1).fill().map(() => new Array(nums2.length + 1).fill(0))
                for (let i = 1; i <= nums1.length; i++) {
                    for (let j = 1; j <= nums2.length; j++) {
                        if (nums1[i - 1] == nums2[j - 1]) {
                            dp[i][j] = dp[i - 1][j - 1] + 1
                            result = Math.max(dp[i][j], result)
                        }
                    }
                }

                return result
            }
            findLength([1, 2, 3, 2, 1], [3, 2, 1, 4, 7])
        </script>
    </body>
</html>
